package com.foreveross.taskservice.taskcache;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.foreveross.taskservice.common.CacheDataSpace;
import com.foreveross.taskservice.common.TaskStatusEnum;
import com.foreveross.taskservice.common.model.AbstractTaskModel;

/**
 * 缓存任务的信息查询接口
 * @author Administrator
 *
 */
public interface ITaskCacheQuery {
	/**
	 * 查询指定数据空间和渠道和任务状态的任务数量
	 * @param d
	 * @param channelId
	 * @param status
	 * @return
	 * @throws Exception
	 */
	public long queryTaskSize(CacheDataSpace d,long channelId,TaskStatusEnum status)throws Exception;
	
	/**
	 * 根据数据空间、渠道、任务状态分页获得任务详情
	 * 默认都是倒序的排序方式
	 * @param d
	 * @param channelId
	 * @param status
	 * @param offset
	 * @param count
	 * @return
	 * @throws Exception
	 */
	public List<AbstractTaskModel> queryTaskDetailInfo(CacheDataSpace d,long channelId,TaskStatusEnum status,int offset,int count)throws Exception;
	/**
	 * 根据指定任务创建日期、任务类型、任务渠道、任务状态分页获得任务详情
	 * @param d
	 * @param taskType
	 * @param channelId
	 * @param status
	 * @param offset
	 * @param count
	 * @return
	 * @throws Exception
	 */
	public List<AbstractTaskModel> queryTaskDetailInfo(Date d,int taskType,long channelId,TaskStatusEnum status,int offset,int count)throws Exception;
	
	/**
	 * 根据数据空查询指定渠道的所有完成的任务数量
	 * @param d
	 * @param channelId
	 * @return
	 * @throws Exception
	 */
	public long queryFinishTaskSize(CacheDataSpace d,long channelId)throws Exception;
	/**
	 * 根据指定任务创建日期、任务类型、任务渠道查询所有完成的任务数量
	 * @param d
	 * @param taskType
	 * @param channelId
	 * @return
	 * @throws Exception
	 */
	public long queryFinishTaskSize(Date d,int taskType,long channelId)throws Exception;
	
	
	
	/**
	 * 统计执行渠道的指定任务状态的数量
	 * @param channelIds
	 * @return
	 * @throws Exception
	 */
	public Map<Long,Map<TaskStatusEnum,Long>> queryTaskSize(CacheDataSpace d,long[] channelIds,TaskStatusEnum[] status)throws Exception;
	
	
	/**
	 * 查询某渠道所有的抓取数量
	 * @param channelId
	 * @return
	 * @throws Exception
	 */
	public long queryChannelAllCrawlCount(CacheDataSpace d,long channelId)throws Exception;
	public long queryChannelAllCrawlCount(Date d,int taskType,long channelId)throws Exception;
	public long[] queryChannelAllCrawlCounts(CacheDataSpace d,long[] channelIds)throws Exception;
	public long[] queryChannelAllCrawlCounts(Date d,int taskType,long[] channelIds)throws Exception;
	/**
	 * 查询某渠道所有的网页流量统计
	 * @param channelId
	 * @return
	 * @throws Exception
	 */
	public long queryChannelAllByteLength(CacheDataSpace d,long channelId)throws Exception;
	public long queryChannelAllByteLength(Date d,int taskType,long channelId)throws Exception;
	public long[] queryChannelAllByteLength(CacheDataSpace d,long[] channelIds)throws Exception;
	public long[] queryChannelAllByteLength(Date d,int taskType,long[] channelIds)throws Exception;
	
	/**
	 * 等待任务中的最大优先级
	 * 如果没有任务则返回 null
	 * @param d
	 * @param channelId
	 * @return
	 * @throws Exception
	 */
	public Integer queryWaitTaskMaxPriority(CacheDataSpace d,long channelId)throws Exception;
	public Integer queryWaitTaskMaxPriority(Date d,int taskType,long channelId)throws Exception;
	
	
	/**
	 * 高级查询
	 * 根据查询条件进行查询
	 * @param space
	 * @param condition
	 * @param count 允许返回最大查询结果数
	 * @return
	 * @throws Exception
	 */
	public QueryResult query(CacheDataSpace space,QueryCondition condition,int count)throws Exception;
	/**
	 * 高级查询
	 * 根据查询结果的缓存结果进行查询
	 * 对查询结果会进行一段时间内的缓存
	 * 
	 * @param resultId
	 * @param offset
	 * @param count
	 * @return
	 * @throws Exception
	 */
	public QueryResult query(String resultId,int offset,int count)throws Exception;
	
	/**
	 * 根据任务id查询结果
	 * @param taskId
	 * @return
	 * @throws Exception
	 */
	public AbstractTaskModel query(String taskId)throws Exception;
	/**
	 * 根据任务id查询结果集
	 * @param taskIds
	 * @return
	 * @throws Exception
	 */
	public List<AbstractTaskModel> query(String ...taskIds)throws Exception;
	
	
}
